package com.yyt.libsrc.net;

import com.yyt.libsrc.conf.Consts;

import java.util.HashMap;
import java.util.Map;

import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.schedulers.Schedulers;
import top.lixb.libcommon.net.CommonCallback;
import top.lixb.libcommon.net.NetApiHelper;

public class NetUtil {

    public static final String seller_api = "api/json/seller.do";
    public static final String home_api = "api/json/home.do";
    public static final String order_api = "api/json/order.do";
    public static void sellerPost(Map<String,String> params, CommonCallback callback) {
       post(Consts.URL.SERVER,seller_api,params,callback);
    }

    public static void sellerGet(Map<String,String> params, CommonCallback callback) {
        get(Consts.URL.SERVER,seller_api,params,callback);
    }

    public static void homePost(Map<String,String> params, CommonCallback callback) {
        post(Consts.URL.SERVER,home_api,params,callback);
    }

    public static void homeGet(Map<String,String> params, CommonCallback callback) {
        get(Consts.URL.SERVER,home_api,params,callback);
    }

    public static void orderPost(Map<String,String> params, CommonCallback callback) {
        post(Consts.URL.SERVER,order_api,params,callback);
    }

    public static void orderGet(Map<String,String> params, CommonCallback callback) {
        get(Consts.URL.SERVER,order_api,params,callback);
    }


    public static void get(String baseUrl,String subUrl,Map<String,String> params, CommonCallback callback) {
        NetApiHelper.createNetApi(baseUrl)
                .commonGetRequest(subUrl,params)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(callback)
        ;
    }


    public static void post(String baseUrl,String subUrl,Map<String,String> params, CommonCallback callback) {
        NetApiHelper.createNetApi(baseUrl)
                .commonPostRequest(subUrl,params)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(callback)
        ;
    }



}
